﻿@page "/credential/create"
@attribute [Authorize(Roles = "User, Administrator")]
@inherits OwningComponentBase<ICovenantService>

@using Covenant.Core
@using Covenant.Models.Covenant
@inject NavigationManager NavigationManager

<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3">
    <h1 class="h2">Create Credential</h1>
</div>

<CredentialForm Credential="Credential" OnSubmit="OnCreate" SubmitIcon="plus" SubmitLabel="Create" />

@code {
    [Parameter]
    public CapturedCredential Credential { get; set; } = new CapturedPasswordCredential();

    private async Task OnCreate(CapturedCredential credential)
    {
        switch (credential.Type)
        {
            case CredentialType.Password:
                this.Credential = await Service.CreatePasswordCredential((CapturedPasswordCredential)credential);
                break;
            case CredentialType.Hash:
                this.Credential = await Service.CreateHashCredential((CapturedHashCredential)credential);
                break;
            case CredentialType.Ticket:
                this.Credential = await Service.CreateTicketCredential((CapturedTicketCredential)credential);
                break;
        }
        NavigationManager.NavigateTo("/data");
    }
}
